package com.meteor.raft.persistent;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author gang.wang1903@xiaobao100.cn
 * @Date: 2019/7/15 8:13 PM
 * raft数据存储，只用于简单的数据分发演示
 */
@Slf4j
@Component
public class RaftData {

    //用户节点数据存储，不做持久化操作
    private final static Map<String, String> clusterMap = new HashMap<String, String>();

    /**
     * 获取存储数据
     * @param key
     * @return
     */
    public String getData(String key){
        log.info("start get data:{}",key);
        return clusterMap.get(key);
    }

    /**
     * 保存
     * @param key
     * @param value
     */
    public void saveData(String key,String value){
        log.info("start save data:key:{},value:{}",key,value);
        clusterMap.put(key,value);
    }

    /**
     * 更新
     * @param key
     * @param value
     */
    public void updateData(String key,String value){
        log.info("start update data:key:{},value:{}",key,value);
        clusterMap.put(key,value);
    }
}
